<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
	    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	    <title>确认密码</title>
	    <link rel="stylesheet" href="../../css/mui.min.css" />
	    <link rel="stylesheet" href="../../css/own.css" />
	    <script type="text/javascript" src="../../js/mui.min.js"></script>   
	    <script type="text/javascript" src="../../js/common.js"></script>
	    <script src="../../js/jquery-1.11.3.js"></script>
	    <link rel="stylesheet" href="../../css/quotation.css" />
	    <style>
	    	body{
	    		background-color: #2B2B2B;
	    	}
	    </style>
	</head>
	<body>
		<header class="mui-bar mui-bar-nav own-topbg">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" id="back"><i>返回</i></a>
			<h1 class="mui-title">设置密码</h1>		
			<a href="javascript:void(0)" class="top-tel" id="online">在线客服</a>
		</header>
		<input type="hidden"  placeholder="请输入您的密码" id='mobile'/>
		<input type="hidden"  placeholder="请输入您的密码" id='code'/>
		<div class="mui-content">
			<div id="inputList">
				<div class="commStyle">
					<label>设置密码：</label>
					<input type="password"  placeholder="请输入您的登录密码" id='password'  oninput="checkValue()" autocomplete="off" onkeyup="value=value.replace(/[\W]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"/>
					<img src="../../images/close.png" id="accountClear">
				</div>
				<div class="commStyle">
					<label>确认密码：</label>
					<input type="password"  placeholder="请再次输入密码" id="confirm_password" oninput="checkValue()" autocomplete="off" onkeyup="value=value.replace(/[\W]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"/>
					<img src="../../images/close.png" id="passwordClear">
				</div>
				<div class="mui-content-padded">
					<button  class="mui-btn mui-btn-block" id="operateLogin">立即注册</button>
				</div>
				<div class="commStyle"  id="resigterDiv">
					<a id="loginDiv"  href="javascript:void(0)">已有账号？立即登录</a>
				</div>
			</div>
			<p id="callService">客服热线：400-180-1860</p>
		</div>
		<script>
			tzdr.online();
			mui.plusReady(function(){
				var width=window.innerWidth;
					$(".commStyle input").css({
						"width":width-120+"px",
					});
				var web=plus.webview.currentWebview();
				var mobile=web.mobile;
				var code = web.code;
				var mobile = web.mobile;
				
				document.getElementById("mobile").value = mobile;
			$("#accountClear").click(function(){
				$("#password").val("");
				checkValue();
			});
			$("#passwordClear").click(function(){
				$("#confirm_password").val("");
				checkValue();
			})
			
			document.getElementById("operateLogin").addEventListener("tap",function(){
				registUser()
			});
			document.getElementById("loginDiv").addEventListener("tap",function(){
				mui.openWindow({
					url:"login.html",
					id:"login.html"
				})
			});
			document.getElementById("callService").addEventListener("tap",function(){
				mui.callService();
			});
//			document.getElementById("telBtn").addEventListener("tap",function(){
//				mui.callService();
//			})
			function registUser(){
				var password= document.getElementById("password").value;
				var password2= document.getElementById("confirm_password").value;
				console.log(mobile)
				var channel=null;
					if(plus.storage.getItem("apk") != null){
						channel=plus.storage.getItem("apk");
					}else{
						channel="57b2d65067e58e601d00258a";
					}
					if(mui.isnull(password)){
						mui.toast("登录密码不能为空！");
						return;
					}
					if(mui.isnull(password2)){
						mui.toast("确认密码不能为空！");
						return;
					}
					
					if(!tzdr.validate_password(password)){
						mui.toast("密码由6-16位数字和字母组成。");
						return;
					}
					//校验登录密码与确认密码是否一致
					if(password!=password2){
						mui.toast("两次输入密码不一致，请重新输入");
						return;
					}
				//plus.nativeUI.showWaiting();
				console.log(mobile+"=="+code+"password"+password)
				mui.app_request('/regist',{ 
      			 'mobile':mobile,
			    'password':password,
			    'parentGeneralizeId':" ",
				 'channel':channel,
				 'code':code
	      		},function(result){
//	    				mui.toast("恭喜您注册成功！");
	      				//存储用户信息
//	    				mui.cacheUser.save(result.data.token,result.data.secret,mobile);
	    				plus.nativeUI.closeWaiting();
	    				//openMockAccount(mobile,password);
	    				mui.confirm("您已注册成功赶紧去登录吧！", "提示", ["确定"], function(e) {
							if(e.index == 0) {
								mui.openWindow("login.html");
							}
						})
	      		},function(result){
	      			if(result.code == 2) {
							mui.toast("注册失败！");
							return;
						} else if(result.code == 3) {
							mui.toast("手机号码已经存在！");
							return;
						} else if(result.code == 4) {
							mui.toast("验证码错误或为空！");
							return;
						} else if(result.code == 5) {
							mui.toast("验证码失效！");
							return;
						} else if(result.code == 6) {
							mui.toast("推广码错误！");
							return;
						} else {
							mui.toast("系统繁忙，请稍后再试！"+result.message);
							return;
						}
	      		
	      		});
			}
			})
			function openMockAccount(username,password){
				mui.app_request("/mock/trade/openMock",
							{"username":username,"password":password},
							function(result){
								console.log("添加模拟账号成功");
							},function(result){
								console.log("添加模拟账号失败");
							}
						)
    		}
			/*按钮变色*/
			function checkValue(){
				var password=$("#password").val();
				var codeInput=$("#confirm_password").val();
				if(password.length>0 && codeInput.length>0){
					$("#operateLogin").css({
						"background-color":"#fcc900"
					});
				}else{
					$("#operateLogin").css({
						"background-color":"#cccccc"
					});
				}
				if(password=="" || password==null || password.length==0) {
					$("#accountClear").css({
						"display": "none"
					});
				}
				if(codeInput=="" || codeInput==null || codeInput.length==0){
					$("#passwordClear").css({
					"display":"none"
					});
				};
				if(password.length>0){
					$("#accountClear").css({
						"display":"block"
					});
				}
				if(codeInput.length>0){
					$("#passwordClear").css({
						"display":"block"
					});
				}
			}
			/*
			 * 下方的客服热线
			 */
				var i = 0 ;
				$(window).resize(function() {
					if(i % 2 == 0){  
						$("#callService").css("display","none");
					}else{
						$("#callService").css("display","block");
					}
					i++; 
				});
		</script>
	</body>
</html>
